package com.example.expresscabinet.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.expresscabinet.common.Result;
import com.example.expresscabinet.model.user;
import com.example.expresscabinet.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user")
public class userController {

    @Autowired
    IUserService userService;



    //用户登录
    @PostMapping(value = "/login")
    public Result<?> login(@RequestBody user user){

       Result result=userService.existUser(user);
       if(result.getCode()=="0"){
           return result;
       }
       else{
           return result;
       }
    }


    //普通用户注册
    @PostMapping(value = "/register")
    public Result<?> register(@RequestBody user user){

        Result result=userService.addUser(user);
        return result;
    }

    //管理员查询当前派送件情况
    @GetMapping(value="/query")
    public Result<?> query(){
        int []res=userService.queryList();
        return Result.success(res);
    }

    //管理员查询快递员列表
    @GetMapping(value="/queryExpressman")
    public Result<?> queryExpressman(@RequestParam int pageNum,
                                  @RequestParam int pageSize){
        Page<user> expressmanList=userService.queryExpressman(pageNum,pageSize);
        return Result.success(expressmanList);
    }

    //管理员删除快递员
    @GetMapping(value="/deleteExpressman/{tel}")
    public Result<?> query(@PathVariable String tel){
        Result res=userService.deleteExpressman(tel);
        return Result.success(res);
    }

}
